﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using Willson.JsbManager.Bll;
using Willson.JsbManager.Comm;
using Willson.JsbManager.BllEntity;
using UtilityLibrary.WinControls;

namespace Willson.JsbManager.UI
{
    public partial class MainToolForm : WeifenLuo.WinFormsUI.Docking.DockContent
    {
        private MainForm main = null;
        
        public MainToolForm(MainForm main)
        {
            this.main = main;
            InitializeComponent();
        }

        public void InitMenu(int user_id)
        {
            List<BEParentMenuInfo> list = null;
            List<BEChildMenuInfo> clist = null;

            int index = 0;

            list = BLLFactory<BLLMenuInfo>.Instance.GetParentMenuInfo(user_id);

            IEnumerator<BEParentMenuInfo> ator = list.GetEnumerator();

            while (ator.MoveNext())
            {
                OutlookBarBand outlookShortcutsBand = new OutlookBarBand(ator.Current.Menu_name);
                outlookShortcutsBand.SmallImageList = this.imageList;
                outlookShortcutsBand.LargeImageList = this.imageList;
                outlookShortcutsBand.Background = Color.White;

                clist = BLLFactory<BLLMenuInfo>.Instance.GetChildMenuInfo(ator.Current.Menu_id);

                IEnumerator<BEChildMenuInfo> cator = clist.GetEnumerator();

                index = 0;

                while (cator.MoveNext())
                {
                    OutlookBarItem item = new OutlookBarItem();
                    WinInfo info = new WinInfo();
                    info.Form_name = cator.Current.MenuWindow;
                    info.Menu_id = cator.Current.Id;
                    info.User_id = user_id;
                    info.Menu_isshow = cator.Current.MenuIsshow;
                    item.Text = cator.Current.MenuName;
                    item.Tag = info;
                    item.ImageIndex = index++;

                    outlookShortcutsBand.Items.Add(item);
      
                }
                
                this.outlookBar.Bands.Add(outlookShortcutsBand);
            }
             
        }

        private void outlookBar_ItemClicked(OutlookBarBand band, OutlookBarItem item)
        {
            WinInfo info = item.Tag as WinInfo;

            if (info.Menu_isshow == 1)
                main.OpenWindows(item.Tag as WinInfo,OpenWindowType.Show);
            else
                main.OpenWindows(item.Tag as WinInfo, OpenWindowType.ShowDialg);
            
        }
    }
}
